<% layout("/layouts/micro.html"){ %>
<div class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<div class="layui-inline">
					<label>文件名称：</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="fileName" id="fileName" autocomplete="off">
					</div>
					<label>文件后缀：</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="fileExt" id="fileExt" autocomplete="off">
					</div>
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-normal addoss_btn">添加</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
			</div>
		</blockquote>
		<table id="ossList" lay-filter="ossList"></table>

		<!--操作-->
		<script type="text/html" id="ossListBar">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
			<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">下载</a>
		</script>
	</form>
</div>

<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //列表
        var tableIns = table.render({
            elem: '#ossList',
            url : '${ctx}/oss/oss/listAjax',
            cellMinWidth : 95,
            page : true,
            request: {
                pageName: 'pageNo', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            height : "full-125",
            limit : 15,
            limits : [10,15,20,25],
            id : "ossListTable",
            cols : [[
                	{type: "checkbox", fixed:"left", width:50},
	               /*  {field:'filePath', title: '图片',width:80,templet:function(d){
	                    return '<img src="'+d.filePath+'" style="width: 28px;height:28px;">'
	                }}, */
					{field:'fileName', title: '文件名称'},
					{field:'fileExt', title: '文件后缀'},
					{field:'fileLengthLabel', title: '文件大小'},
					{field:'fileId', title: '文件ID'},
					{field:'statusLabel', title: '状态'},
					{field:'createDate', title: '创建时间'},
					{field:'updateDate', title: '更新时间'},
				<%if(shiro.hasPermission("oss:oss:edit")){%>
					{title: '操作', width:170, templet:'#ossListBar',fixed:"right",align:"center"}
			 	<%}%>
            ]]
        });

        //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click",function(){
				var fileName = $('#fileName');
				var fileExt = $('#fileExt');
			table.reload("ossListTable",{
				page: {
					curr: 1 //重新从第 1 页开始
				},
				where: {
					fileName : fileName.val(),
					fileExt : fileExt.val(),
				}
			})
        });

        //添加
        function addoss(id){
        	Common.openDlg("${ctx}/oss/oss/form?id="+id,"添加附件管理");
        }
        $(".addoss_btn").click(function(){
            var id = '${oss.id}';
            addoss(id);
        })


        //批量删除
        $(".delAll_btn").click(function(){
            var checkStatus = table.checkStatus('ossListTable'),
                data = checkStatus.data,
                selectedIds = [];
            if(data.length > 0) {
                for (var i in data) {
                    selectedIds.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("${ctx}/oss/oss/batchDelete",{selectedIds:selectedIds.join(",")},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                })
            }else{
                layer.msg("请选择需要删除的数据");
            }
        })

        //列表操作
        table.on('tool(ossList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addoss(data.id);
            } else if(layEvent === 'del'){ //删除
               layer.confirm('确定删除选中数据？',{icon:3, title:'确认信息'},function(index){
                    $.post("${ctx}/oss/oss/delete",{id:data.id},function(result){
                        if(result.code=="0"){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'look'){ //预览
            	window.location = "${ctxPath}"+data.fileId;
            }
        });

    })
</script>
<%}%>